<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>isSame() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>isSame()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>isSame()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/query/is-same/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/05-query/02-is-same.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isSame(Moment|String|Number|Date|Array);
moment().isSame(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>&#x68C0;&#x67E5;&#x4E00;&#x4E2A; moment &#x662F;&#x5426;&#x4E0E;&#x53E6;&#x4E00;&#x4E2A; moment &#x76F8;&#x540C;&#x3002;
&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x89E3;&#x6790;&#x4E3A; moment&#xFF08;&#x5982;&#x679C;&#x5C1A;&#x672A;&#x89E3;&#x6790;&#xFF09;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSame(&apos;2010-10-20&apos;); // true
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x5C06;&#x7C92;&#x5EA6;&#x9650;&#x5236;&#x4E3A;&#x6BEB;&#x79D2;&#x4EE5;&#x5916;&#x7684;&#x5355;&#x4F4D;&#xFF0C;&#x5219;&#x5C06;&#x5355;&#x4F4D;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSame(&apos;2009-12-31&apos;, &apos;year&apos;);  // false
moment(&apos;2010-10-20&apos;).isSame(&apos;2010-01-01&apos;, &apos;year&apos;);  // true
moment(&apos;2010-10-20&apos;).isSame(&apos;2010-12-31&apos;, &apos;year&apos;);  // true
moment(&apos;2010-10-20&apos;).isSame(&apos;2011-01-01&apos;, &apos;year&apos;);  // false
</code></pre>
<p>&#x5F53;&#x5305;&#x542B;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x5219;&#x5B83;&#x5C06;&#x4F1A;&#x5339;&#x914D;&#x6240;&#x6709;&#x7B49;&#x4E8E;&#x6216;&#x66F4;&#x5927;&#x7684;&#x5355;&#x4F4D;&#x3002;
&#x4F20;&#x5165; <code>month</code> &#x5C06;&#x4F1A;&#x68C0;&#x67E5; <code>month</code> &#x548C; <code>year</code>&#x3002;
&#x4F20;&#x5165; <code>day</code> &#x5C06;&#x4F1A;&#x68C0;&#x67E5; <code>day</code>&#x3001;<code>month</code> &#x548C; <code>year</code>&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-01-01&apos;).isSame(&apos;2011-01-01&apos;, &apos;month&apos;); // false, &#x4E0D;&#x540C;&#x7684;&#x5E74;&#x4EFD;
moment(&apos;2010-01-01&apos;).isSame(&apos;2010-02-01&apos;, &apos;day&apos;);   // false, &#x4E0D;&#x540C;&#x7684;&#x6708;&#x4EFD;
</code></pre>
<p>&#x4E0E; <code>moment#isAfter</code> &#x548C; <code>moment#isBefore</code> &#x4E00;&#x6837;&#xFF0C;<code>moment#startOf</code> &#x652F;&#x6301;&#x7684;&#x4EFB;&#x4F55;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#x4E5F;&#x9002;&#x7528;&#x4E8E; <code>moment#isSame</code>&#x3002;</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
<p>&#x5982;&#x679C;&#x4E24;&#x4E2A; moment &#x7684;&#x65F6;&#x533A;&#x4E0D;&#x540C;&#xFF0C;&#x5219;&#x7B2C;&#x4E00; moment &#x7684;&#x65F6;&#x533A;&#x4F1A;&#x88AB;&#x7528;&#x4E8E;&#x6BD4;&#x8F83;&#x3002;</p>
<pre><code class="language-javascript">// &#x6CE8;&#x610F;&#xFF1A;&#x6FB3;&#x5927;&#x5229;&#x4E9A;/&#x6089;&#x5C3C;&#x5728;&#x8FD9;&#x4E9B;&#x65E5;&#x671F;&#x7684; UTC+11:00
moment.tz(&quot;2018-11-09T10:00:00&quot;, &quot;Australia/Sydney&quot;).isSame(moment.tz(&quot;2018-11-08T12:00:00&quot;, &quot;UTC&quot;), &quot;day&quot;); // false
moment.tz(&quot;2018-11-08T12:00:00&quot;, &quot;UTC&quot;).isSame(moment.tz(&quot;2018-11-09T10:00:00&quot;, &quot;Australia/Sydney&quot;), &quot;day&quot;); // true
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;<code>moment().isSame()</code> &#x5177;&#x6709;&#x672A;&#x5B9A;&#x4E49;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x4E14;&#x4E0D;&#x5E94;&#x88AB;&#x4F7F;&#x7528;&#xFF01;
&#x5982;&#x679C;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x5FEB;&#x901F;&#xFF0C;&#x5219;&#x521D;&#x59CB;&#x521B;&#x5EFA;&#x7684; moment &#x5C06;&#x4F1A;&#x4E0E;isSame &#x4E2D;&#x521B;&#x5EFA;&#x7684;&#x8981;&#x6267;&#x884C;&#x68C0;&#x67E5;&#x7684;&#x76F8;&#x540C;&#xFF0C;&#x56E0;&#x6B64;&#x7ED3;&#x679C;&#x5C06;&#x4F1A;&#x4E3A; <code>true</code>&#x3002;
&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x901F;&#x5EA6;&#x8F83;&#x6162;&#xFF0C;&#x5219;&#x6709;&#x53EF;&#x80FD;&#x5728; isSame &#x4E2D;&#x521B;&#x5EFA;&#x7684; moment &#x53EF;&#x6D4B;&#x91CF;&#x5730;&#x5728; <code>moment()</code> &#x4E2D;&#x521B;&#x5EFA;&#x7684;&#x4E4B;&#x540E;&#xFF0C;&#x56E0;&#x6B64;&#x8BE5;&#x8C03;&#x7528;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE; <code>false</code>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isSame(Moment|String|Number|Date|Array);
moment().isSame(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>Check if a moment is the same as another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSame(&apos;2010-10-20&apos;); // true
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSame(&apos;2009-12-31&apos;, &apos;year&apos;);  // false
moment(&apos;2010-10-20&apos;).isSame(&apos;2010-01-01&apos;, &apos;year&apos;);  // true
moment(&apos;2010-10-20&apos;).isSame(&apos;2010-12-31&apos;, &apos;year&apos;);  // true
moment(&apos;2010-10-20&apos;).isSame(&apos;2011-01-01&apos;, &apos;year&apos;);  // false
</code></pre>
<p>When including a second parameter, it will match all units equal or larger. Passing in <code>month</code> will check <code>month</code> and <code>year</code>. Passing in <code>day</code> will check <code>day</code>, <code>month</code>, and <code>year</code>.</p>
<pre><code class="language-javascript">moment(&apos;2010-01-01&apos;).isSame(&apos;2011-01-01&apos;, &apos;month&apos;); // false, different year
moment(&apos;2010-01-01&apos;).isSame(&apos;2010-02-01&apos;, &apos;day&apos;);   // false, different month
</code></pre>
<p>Like <code>moment#isAfter</code> and <code>moment#isBefore</code>, any of the units of time that are supported for <code>moment#startOf</code> are supported for <code>moment#isSame</code>.</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
<p>If the two moments have different timezones, the timezone of the first moment will be used for the comparison.</p>
<pre><code class="language-javascript">// Note: Australia/Sydney is UTC+11:00 on these dates
moment.tz(&quot;2018-11-09T10:00:00&quot;, &quot;Australia/Sydney&quot;).isSame(moment.tz(&quot;2018-11-08T12:00:00&quot;, &quot;UTC&quot;), &quot;day&quot;); // false
moment.tz(&quot;2018-11-08T12:00:00&quot;, &quot;UTC&quot;).isSame(moment.tz(&quot;2018-11-09T10:00:00&quot;, &quot;Australia/Sydney&quot;), &quot;day&quot;); // true
</code></pre>
<p><em>NOTE</em>: <code>moment().isSame()</code> has undefined behavior and should not be used! If
the code runs fast the initial created moment would be the same as the one
created in isSame to perform the check, so the result would be <code>true</code>. But
if the code runs slower it&apos;s possible that the moment created in isSame is
measurably after the one created in <code>moment()</code>, so the call would return
<code>false</code>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>